<?php
// +----------------------------------------------------------------------
// | 有小象汇 自研正版源码 赋能开发者
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 http://www.uxphp.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 有小象汇并不是自由软件，未经许可不能去掉有小象汇相关版权
// +----------------------------------------------------------------------
// | Author:  有小象汇
// +----------------------------------------------------------------------

namespace app\adminapi\controller\v1\car;


use app\adminapi\controller\AuthController;
use app\services\car\CarTypeServices;
use think\facade\App;

/**
 * Class CarType
 * @package app\adminapi\controller\v1\shendeng
 */
class CarType extends AuthController
{
    public function __construct(App $app,CarTypeServices $services)
    {
        parent::__construct($app);
        $this->services = $services;
    }
    /**
     * 列表
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getList(){
        $where = $this->request->getMore([
            ['is_del',0],
            ['status',''],
            ['place_id',''],
            ['type_info_id',''],
        ]);
        $field = '*';
        $admin = $this->request->adminInfo();
        if($admin['store_id']) $where['place_id'] = $admin['store_id'];
        return app('json')->success($this->services->getList($where,$field,true));
    }
    /**
     * 添加/修改
     * @return mixed
     * @throws \FormBuilder\Exception\FormBuilderException
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function add(){
        $data = $this->request->getMore([
            ['id', 0],
        ]);
        $admin = $this->request->adminInfo();
        return app('json')->success($this->services->add((int)$data['id'],$admin));
    }

    /**
     * 添加/修改保存
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function save(){
        $data = $this->request->postMore([
            ['id', 0],
            ['type_info_id', ''],
            ['place_id', ''],
//            ['price_hour', ''],
            ['price', ''],
            ['sat_price', ''],
            ['sun_price', ''],
            ['zhoumo_price', ''],
            ['base_service_fee', ''],
            ['illegal_deposit', ''],
            ['deposit', ''],
            ['status', ''],
        ]);
        $this->services->save((int)$data['id'], $data);
        return app('json')->success('提交成功');
    }

    /**
     * 删除
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function delete(){
        $data = $this->request->getMore([
            ['id', 0],
        ]);
        if (!$data['id']) return app('json')->fail('参数错误');
        return app('json')->success($this->services->delType((int)$data['id']));
    }

    /**
     * 显示/隐藏
     * @param string $status
     * @param string $id
     * @param string $type
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function setShow(string $status = '',string $id = '',string $type = ''){
        if ($status == '' || $id == '' || $type == '') return app('json')->fail('缺少参数');
        return app('json')->success($this->services->setShow((int)$id, (int)$status,$type));
    }

    /**
     * 车型下拉列表
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getTypeList(){
        $where = $this->request->getMore([
            ['is_del',0],
        ]);
        $field = '*';
        return app('json')->success($this->services->getTypeList($where,$field,false));
    }
    // 车型门店下拉
    public function getType(){
        $admin = $this->request->adminInfo();
        if($admin['store_id']){
            $where['place_id'] = $admin['store_id'];
        }else{
            $where = [];
        }
        return app('json')->success($this->services->getType($where));
    }

    /**
     * 门店车型
     * @return mixed
     */
    public function storeCar(){
        $data = $this->request->getMore([
            ['place_id',''],
        ]);
        return app('json')->success($this->services->storeCar((int)$data['place_id']));
    }
}
